package com.csun.cmny.provider.web.rpc;

import com.csun.cmny.provider.model.vo.LifeRoomBuildingVo;
import com.csun.cmny.provider.model.vo.RoomBuildingVo;
import com.csun.cmny.provider.pojo.Room;
import com.csun.cmny.provider.service.OmcRoomFeignApi;
import com.csun.cmny.provider.service.RoomService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-04-19 13:15
 * @Description: the class omc room feign client
 */
@Slf4j
@RestController
public class OmcRoomFeignClient implements OmcRoomFeignApi {

    @Resource
    private RoomService roomService;

    @Override
    public Wrapper<RoomBuildingVo> queryRoomBuildingByRoomId(@RequestParam("roomId") Integer roomId) {

        RoomBuildingVo roomBuildingVo = roomService.queryRoomBuildingByRoomId(roomId);

        return WrapMapper.ok(roomBuildingVo);
    }

    @Override
    public Wrapper<List<LifeRoomBuildingVo>> listRoomByGroupId(@RequestParam("groupId") Long groupId) {

        List<LifeRoomBuildingVo> list = roomService.listRoomByGroupId(groupId);

        return WrapMapper.ok(list);
    }

    @Override
    public Wrapper<List<Integer>> listBedByRoomId(@RequestParam("roomId") Integer roomId) {

        List<Integer> collect = Lists.newArrayList();
        Room room = roomService.selects(roomId);
        if(room != null){
            if(room.getBedList() != null && room.getBedList().size() > 0){
                collect = room.getBedList().stream().map(b -> b.getBedId()).collect(Collectors.toList());
            }
        }
        return WrapMapper.ok(collect);
    }


}
